package com.example.my_self_view

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment

class ItemFragment: Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val view = inflater.inflate(R.layout.fragment_item, null)
        val tv = view.findViewById<TextView>(R.id.text_view)
        val bundle = arguments
        tv.text = bundle?.getString("title") ?: "666"
        return view
    }

    companion object{
        fun newInstance(item: String): ItemFragment {
            val itemFragment = ItemFragment()
            val bundle = Bundle()
            bundle.putString("title", item)
            itemFragment.arguments = bundle
            return itemFragment
        }
    }
}